#include <reg52.h>

sbit SH_CP = P3^6;
sbit ST_CP = P3^5;
sbit DS = P3^4;

void delay_ms(unsigned int ms) {
    unsigned int i, j;
    for(i = ms; i > 0; i--)
        for(j = 110; j > 0; j--);
}

void send_data(unsigned char dat) {
    unsigned char i;
    for(i = 0; i < 8; i++) {
        DS = (dat & 0x80) ? 1 : 0;
        dat <<= 1;
        SH_CP = 0;
        SH_CP = 1;
    }
    ST_CP = 0;
    ST_CP = 1;
}

void main() {
    unsigned char i;
    
    while(1) {
   
        for(i = 0; i < 8; i++) {
            send_data(0xFE);  
            switch(i) {
                case 0: P0 = 0x7F; break; // 01111111 
                case 1: P0 = 0xBF; break; // 10111111 
                case 2: P0 = 0xDF; break; // 11011111 
                case 3: P0 = 0xEF; break; // 11101111 
                case 4: P0 = 0xF7; break; // 11110111 
                case 5: P0 = 0xFB; break; // 11111011 
                case 6: P0 = 0xFD; break; // 11111101 
                case 7: P0 = 0xFE; break; // 11111110 
            }
            delay_ms(200);  
        }
    }
}



//#include <reg52.h>

//sbit SH_CP = P3^6;
//sbit ST_CP = P3^5;
//sbit DS = P3^4;

//void delay_ms(unsigned int ms) {
//    unsigned int i, j;
//    for(i = ms; i > 0; i--)
//        for(j = 110; j > 0; j--);
//}

//void send_data(unsigned char dat) {
//    unsigned char i;
//    for(i = 0; i < 8; i++) {
//        DS = (dat & 0x80) ? 1 : 0;
//        dat <<= 1;
//        SH_CP = 0;
//        SH_CP = 1;
//    }
//    ST_CP = 0;
//    ST_CP = 1;
//}

//void main() {
//    unsigned char i, j;
//    unsigned char heart_cols[] = {
//        0x30, 0x78, 0xFC, 0xFE, 0xFE, 0xFC, 0x78, 0x30
//    };
//    
//    unsigned char rows[] = {0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE};
//    
//    while(1) {
//        for(j = 0; j < 8; j++) {
//            send_data(heart_cols[j]);
//            P0 = rows[j];
//            delay_ms(2);
//        }
//    }
//}